<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html>
<html lang="en">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!-- qsgmaterial.cpp -->
  <title>QSGMaterial 类 | Qt Quick 5.12.3</title>
  <link rel="stylesheet" type="text/css" href="style/offline-simple.css" />
  <script type="text/javascript">
    document.getElementsByTagName("link").item(0).setAttribute("href", "style/offline.css");
    // loading style sheet breaks anchors that were jumped to before
    // so force jumping to anchor again
    setTimeout(function() {
        var anchor = location.hash;
        // need to jump to different anchor first (e.g. none)
        location.hash = "#";
        setTimeout(function() {
            location.hash = anchor;
        }, 0);
    }, 0);
  </script>
</head>
<body>
<div class="header" id="qtdocheader">
  <div class="main">
    <div class="main-rounded">
      <div class="navigationbar">
        <table><tr>
<td ><a href="../qtdoc/index.html">Qt 5.12</a></td><td ><a href="qtquick-index.html">Qt Quick 模块</a></td><td ><a href="qtquick-module.html">C++ 类</a></td><td >QSGMaterial</td></tr></table><table class="buildversion"><tr>
<td id="buildversion" width="100%" align="right"><a href="qtquick-index.html">Qt 5.12.3 参考指南</a></td>
        </tr></table>
      </div>
    </div>
<div class="content">
<div class="line">
<div class="content mainContent">
<div class="sidebar">
<div class="toc">
<h3><a name="toc">目录</a></h3>
<ul>
<li class="level1"><a href="#public-types">公用类型</a></li>
<li class="level1"><a href="#public-functions">公用函数</a></li>
<li class="level1"><a href="#details">详细信息</a></li>
</ul>
</div>
<div class="sidebar-content" id="sidebar-content"></div></div>
<h1 class="title">QSGMaterial 类</h1>
<!-- $$$QSGMaterial-brief -->
<p>The <a href="qsgmaterial.html">QSGMaterial</a> class encapsulates rendering state for a shader program. <a href="#details">更多...</a></p>
<!-- @@@QSGMaterial -->
<div class="table"><table class="alignedsummary">
<tr><td class="memItemLeft rightAlign topAlign">头文件：</td><td class="memItemRight bottomAlign">   <span class="preprocessor">#include &lt;QSGMaterial&gt;</span>
</td></tr><tr><td class="memItemLeft rightAlign topAlign"> qmake:</td><td class="memItemRight bottomAlign"> QT += quick</td></tr><tr><td class="memItemLeft rightAlign topAlign"> 被继承：</td><td class="memItemRight bottomAlign"> <p><a href="qsgflatcolormaterial.html">QSGFlatColorMaterial</a>, <a href="qsgopaquetexturematerial.html">QSGOpaqueTextureMaterial</a>, <a href="qsgsimplematerial.html">QSGSimpleMaterial</a>, and <a href="qsgvertexcolormaterial.html">QSGVertexColorMaterial</a></p>
</td></tr></table></div><ul>
<li><a href="qsgmaterial-members.html">所有成员的列表，包括继承成员</a></li>
</ul>
<a name="public-types"></a>
<h2 id="public-types">公用类型</h2>
<div class="table"><table class="alignedsummary">
<tr><td class="memItemLeft rightAlign topAlign"> enum </td><td class="memItemRight bottomAlign"><b><a href="qsgmaterial.html#Flag-enum">Flag</a></b> { Blending, RequiresDeterminant, RequiresFullMatrixExceptTranslate, RequiresFullMatrix, CustomCompileStep }</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> flags </td><td class="memItemRight bottomAlign"><b><a href="qsgmaterial.html#Flag-enum">Flags</a></b></td></tr>
</table></div>
<a name="public-functions"></a>
<h2 id="public-functions">公用函数</h2>
<div class="table"><table class="alignedsummary">
<tr><td class="memItemLeft rightAlign topAlign"> virtual int </td><td class="memItemRight bottomAlign"><b><a href="qsgmaterial.html#compare">compare</a></b>(const QSGMaterial *<i>other</i>) const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> virtual QSGMaterialShader *</td><td class="memItemRight bottomAlign"><b><a href="qsgmaterial.html#createShader">createShader</a></b>() const = 0</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> QSGMaterial::Flags </td><td class="memItemRight bottomAlign"><b><a href="qsgmaterial.html#flags">flags</a></b>() const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> void </td><td class="memItemRight bottomAlign"><b><a href="qsgmaterial.html#setFlag">setFlag</a></b>(QSGMaterial::Flags <i>flags</i>, bool <i>on</i> = true)</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> virtual QSGMaterialType *</td><td class="memItemRight bottomAlign"><b><a href="qsgmaterial.html#type">type</a></b>() const = 0</td></tr>
</table></div>
<a name="details"></a>
<!-- $$$QSGMaterial-description -->
<div class="descr">
<h2 id="details">详细信息</h2>
<p>The <a href="qsgmaterial.html">QSGMaterial</a> class encapsulates rendering state for a shader program.</p>
<p>The <a href="qsgmaterial.html">QSGMaterial</a> API is very low-level. A more convenient API, which provides almost all the same features, is available through <a href="qsgsimplematerialshader.html">QSGSimpleMaterialShader</a>.</p>
<p>The <a href="qsgmaterial.html">QSGMaterial</a> and <a href="qsgmaterialshader.html">QSGMaterialShader</a> subclasses form a tight relationship. For one scene graph (including nested graphs), there is one unique <a href="qsgmaterialshader.html">QSGMaterialShader</a> instance which encapsulates the <a href="../qtgui/qopenglshaderprogram.html">QOpenGLShaderProgram</a> the scene graph uses to render that material, such as a shader to flat coloring of geometry. Each <a href="qsggeometrynode.html">QSGGeometryNode</a> can have a unique <a href="qsgmaterial.html">QSGMaterial</a> containing the how the shader should be configured when drawing that node, such as the actual color to used to render the geometry.</p>
<p>The <a href="qsgmaterial.html">QSGMaterial</a> has two virtual functions that both need to be implemented. The function <a href="qsgmaterial.html#type">type</a>() should return a unique instance for all instances of a specific subclass. The <a href="qsgmaterial.html#createShader">createShader</a>() function should return a new instance of <a href="qsgmaterialshader.html">QSGMaterialShader</a>, specific to the subclass of <a href="qsgmaterial.html">QSGMaterial</a>.</p>
<p>A minimal <a href="qsgmaterial.html">QSGMaterial</a> implementation could look like this:</p>
<pre class="cpp">

  <span class="keyword">class</span> Material : <span class="keyword">public</span> <span class="type">QSGMaterial</span>
  {
  <span class="keyword">public</span>:
      <span class="type"><a href="qsgmaterialtype.html">QSGMaterialType</a></span> <span class="operator">*</span>type() <span class="keyword">const</span> { <span class="keyword">static</span> <span class="type"><a href="qsgmaterialtype.html">QSGMaterialType</a></span> type; <span class="keyword">return</span> <span class="operator">&amp;</span>type; }
      <span class="type"><a href="qsgmaterialshader.html">QSGMaterialShader</a></span> <span class="operator">*</span>createShader() <span class="keyword">const</span> { <span class="keyword">return</span> <span class="keyword">new</span> Shader; }
  };

</pre>
<p><b>Note: </b>All classes with QSG prefix should be used solely on the scene graph's rendering thread. See <a href="qtquick-visualcanvas-scenegraph.html#scene-graph-and-rendering">Scene Graph and Rendering</a> for more information.</p></div>
<!-- @@@QSGMaterial -->
<div class="types">
<h2>成员类型文档</h2>
<!-- $$$Flag$$$Blending$$$RequiresDeterminant$$$RequiresFullMatrixExceptTranslate$$$RequiresFullMatrix$$$CustomCompileStep -->
<h3 class="flags" id="Flag-enum"><a name="Flag-enum"></a>enum QSGMaterial::<span class="name">Flag</span><br/>flags QSGMaterial::<span class="name">Flags</span></h3>
<div class="table"><table class="valuelist"><tr valign="top" class="odd"><th class="tblConst">Constant</th><th class="tblval">Value</th><th class="tbldscr">Description</th></tr>
<tr><td class="topAlign"><code>QSGMaterial::Blending</code></td><td class="topAlign tblval"><code>0x0001</code></td><td class="topAlign">Set this flag to true if the material requires GL_BLEND to be enabled during rendering.</td></tr>
<tr><td class="topAlign"><code>QSGMaterial::RequiresDeterminant</code></td><td class="topAlign tblval"><code>0x0002</code></td><td class="topAlign">Set this flag to true if the material relies on the determinant of the matrix of the geometry nodes for rendering.</td></tr>
<tr><td class="topAlign"><code>QSGMaterial::RequiresFullMatrixExceptTranslate</code></td><td class="topAlign tblval"><code>0x0004 | RequiresDeterminant</code></td><td class="topAlign">Set this flag to true if the material relies on the full matrix of the geometry nodes for rendering, except the translation part.</td></tr>
<tr><td class="topAlign"><code>QSGMaterial::RequiresFullMatrix</code></td><td class="topAlign tblval"><code>0x0008 | RequiresFullMatrixExceptTranslate</code></td><td class="topAlign">Set this flag to true if the material relies on the full matrix of the geometry nodes for rendering.</td></tr>
<tr><td class="topAlign"><code>QSGMaterial::CustomCompileStep</code></td><td class="topAlign tblval"><code>0x0010</code></td><td class="topAlign">Starting with Qt 5.2, the scene graph will not always call <a href="qsgmaterialshader.html#compile">QSGMaterialShader::compile</a>() when its shader program is compiled and linked. Set this flag to enforce that the function is called.</td></tr>
</table></div>
<p>The Flags type is a typedef for <a href="../qtcore/qflags.html">QFlags</a>&lt;Flag&gt;. It stores an OR combination of Flag values.</p>
<!-- @@@Flag -->
</div>
<div class="func">
<h2>成员函数文档</h2>
<!-- $$$compare[overload1]$$$compareconstQSGMaterial* -->
<h3 class="fn" id="compare"><a name="compare"></a><code>[virtual] </code><span class="type">int</span> QSGMaterial::<span class="name">compare</span>(const <span class="type">QSGMaterial</span> *<i>other</i>) const</h3>
<p>Compares this material to <i>other</i> and returns 0 if they are equal; -1 if this material should sort before <i>other</i> and 1 if <i>other</i> should sort before.</p>
<p>The scene graph can reorder geometry nodes to minimize state changes. The compare function is called during the sorting process so that the materials can be sorted to minimize state changes in each call to <a href="qsgmaterialshader.html#updateState">QSGMaterialShader::updateState</a>().</p>
<p>The this pointer and <i>other</i> is guaranteed to have the same <a href="qsgmaterial.html#type">type</a>().</p>
<!-- @@@compare -->
<!-- $$$createShader[overload1]$$$createShader -->
<h3 class="fn" id="createShader"><a name="createShader"></a><code>[pure virtual] </code><span class="type"><a href="qsgmaterialshader.html">QSGMaterialShader</a></span> *QSGMaterial::<span class="name">createShader</span>() const</h3>
<p>This function returns a new instance of a the <a href="qsgmaterialshader.html">QSGMaterialShader</a> implementatation used to render geometry for a specific implementation of <a href="qsgmaterial.html">QSGMaterial</a>.</p>
<p>The function will be called only once for each material type that exists in the scene graph and will be cached internally.</p>
<!-- @@@createShader -->
<!-- $$$flags[overload1]$$$flags -->
<h3 class="fn" id="flags"><a name="flags"></a><span class="type"><a href="qsgmaterial.html#Flag-enum">QSGMaterial::Flags</a></span> QSGMaterial::<span class="name">flags</span>() const</h3>
<p>Returns the material's flags.</p>
<!-- @@@flags -->
<!-- $$$setFlag[overload1]$$$setFlagQSGMaterial::Flagsbool -->
<h3 class="fn" id="setFlag"><a name="setFlag"></a><span class="type">void</span> QSGMaterial::<span class="name">setFlag</span>(<span class="type"><a href="qsgmaterial.html#Flag-enum">QSGMaterial::Flags</a></span> <i>flags</i>, <span class="type">bool</span> <i>on</i> = true)</h3>
<p>Sets the flags <i>flags</i> on this material if <i>on</i> is true; otherwise clears the attribute.</p>
<!-- @@@setFlag -->
<!-- $$$type[overload1]$$$type -->
<h3 class="fn" id="type"><a name="type"></a><code>[pure virtual] </code><span class="type"><a href="qsgmaterialtype.html">QSGMaterialType</a></span> *QSGMaterial::<span class="name">type</span>() const</h3>
<p>This function is called by the scene graph to return a unique instance per subclass.</p>
<!-- @@@type -->
</div>
        </div>
       </div>
   </div>
   </div>
</div>
<div class="footer">
   <p>
   <acronym title="Copyright">&copy;</acronym> 2019 The Qt Company Ltd.
   Documentation contributions included herein are the copyrights of
   their respective owners.<br/>    The documentation provided herein is licensed under the terms of the    <a href="http://www.gnu.org/licenses/fdl.html">GNU Free Documentation    License version 1.3</a> as published by the Free Software Foundation.<br/>    Qt and respective logos are trademarks of The Qt Company Ltd.     in Finland and/or other countries worldwide. All other trademarks are property
   of their respective owners. </p>
</div>
</body>
</html>
